Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Jan 27, 2026

analog #4554

assertType("non-empty-array<'bar'|'foo'|int, string>", array_replace($array1, $array3));
assertType("non-empty-array<'bar'|'foo'|int, string>", array_replace($array3, $array1));
assertType("non-empty-array<'bar'|'foo'|int, string>&hasOffset('bar')&hasOffset('foo')", array_replace($array1, $array3));
assertType("non-empty-array<'bar'|'foo'|int, string>&hasOffsetValue('bar', '2')&hasOffsetValue('foo', '1')", array_replace($array3, $array1));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this kind of overlaps. should we do something about it, or is it fine?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean the non-empty-array and the hasOffset(Value) ?
I think it's more clear this way, by being explicit.

I dunno if it's currently possible to get a dump

array<...>&hasOffset(..)

It would be weird to be able to get both array or non-empty-array in this situation.

Copy link
Contributor Author

@staabm staabm Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the type is
non-empty-array<'bar'|'foo'|int, string>&hasOffsetValue('bar', '2')&hasOffsetValue('foo', '1')

while some keys in
non-empty-array<'bar'|'foo'|int, string>
are redundant with the accessories in
hasOffsetValue('bar', '2')&hasOffsetValue('foo', '1')

@staabm
Copy link
Contributor Author

staabm commented Jan 28, 2026

@claudepache @VincentLanglet you might be interessted in reviewing this one

@ondrejmirtes ondrejmirtes merged commit 7850b66 into phpstan:2.1.x Feb 11, 2026
632 of 639 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the replace branch February 11, 2026 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants